#include "tim6.h"
#include "stm32f4xx.h"
#include "beep.h"
void tim6_init()
{
	TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
	NVIC_InitTypeDef NVIC_InitTypeDefStruct;
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6,ENABLE);
	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);  
	TIM_TimeBaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
	TIM_TimeBaseInitStructure.TIM_Period = 50000-1 ;
	TIM_TimeBaseInitStructure.TIM_Prescaler = 83;//8399+1 84 / 8399+1  5/100 * 50000 = 0.05
	TIM_TimeBaseInit(TIM6,&TIM_TimeBaseInitStructure);
	TIM_ITConfig(TIM6,TIM_IT_Update,ENABLE);
	
	NVIC_InitTypeDefStruct.NVIC_IRQChannel = TIM6_DAC_IRQn;
	NVIC_InitTypeDefStruct.NVIC_IRQChannelCmd = ENABLE;
	NVIC_InitTypeDefStruct.NVIC_IRQChannelPreemptionPriority = 1;
	NVIC_InitTypeDefStruct.NVIC_IRQChannelSubPriority = 3;
	NVIC_Init(&NVIC_InitTypeDefStruct);
	TIM_Cmd(TIM6,ENABLE);
}
int cout = 0;
void TIM6_DAC_IRQHandler(void)
{
		if(TIM_GetITStatus(TIM6,TIM_IT_Update) == SET)
		{
			cout++;
			if(cout == 10)
			{
				GPIO_ToggleBits(GPIOH,GPIO_Pin_5);
				cout = 0;
			}
			TIM_ClearITPendingBit(TIM6,TIM_IT_Update);
		}
}
	






